<template>
    <div>
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="btn_box">
            <el-button type="primary" size="mini" @click="addmenu">添加</el-button>
            <el-button type="warning" size="mini">批量删除</el-button>
        </div>
        <el-table :data="menusList" style="width: 100%" row-key="id" border lazy 
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
            <el-table-column prop="title" label="名称" sortable></el-table-column>
            <el-table-column label="图标" sortable>
                <template slot-scope="{row}">
                    <i :class="row.icon"></i>
                </template>
            </el-table-column>
            <el-table-column label="类型">
                <template slot-scope="{row}">
                    <el-tag v-if="row.type == 1">目录</el-tag>
                    <el-tag v-else type="success">菜单</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template>
                    <el-button size="mini">编辑</el-button>
                    <el-button size="mini" type="danger">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 添加 -->
        <add-dialog :addInfo="addInfo" :menusList="menusList"></add-dialog>
    </div>
</template>

<script>
import { getMenu } from '@/api/menu';
import addDialog from './components/addDialog.vue';
export default {
    components: { addDialog },
    name: 'MyAppIndex',

    data() {
        return {
            menusList: [],
            addInfo: {
                title: "菜单添加",
                addShow: false
            }
        };
    },

    mounted() {
        this.getMenuList()
    },

    methods: {
        async getMenuList() {
            let res = await getMenu()
            console.log(res);
            this.menusList = res
        },
        addmenu() {
            this.addInfo = {
                title: "菜单添加",
                addShow: true
            }
        }
    },
};
</script>

<style lang="scss" scoped>
.btn_box {
    margin-top: 20px;
    margin-bottom: 20px;
}
</style>